package com.tshopping.controller;

import com.tshopping.bean.Level;
import com.tshopping.service.LevelService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @name: LevelController
 * @description: 管理员类别页面控制器
 * @author: Jackeys
 * @date: 2021-01-08 08:43
 */
@RestController
@RequestMapping("/LevelController")
@CrossOrigin
public class LevelController {

    @Autowired
    private LevelService levelService;

    @PostMapping(value = "/addLevel")
    /**
     * @description 判断管理员添加类别是否成功
     * @Param: name
     * @Param: parent
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 09:18
     */
    public ResponseData addLevel(String name, int parent){
        return levelService.addLevel(name,parent);
    }

    @PostMapping(value = "/updateLevel")
    /**
     * @description 判断管理员修改类别是否成功
     * @Param: name
     * @Param: parent
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 09:14
     */
    public ResponseData updateLevel(String name,int parent,int id){
        return levelService.updateLevel(name,parent,id);
    }

    @PostMapping(value = "/deleteLevel")
    /**
     * @description 判断管理员删除类别是否成功
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 09:27
     */
    public ResponseData deleteLevel(int id){
        return levelService.deleteLevel(id);
    }

    @PostMapping(value = "/getLevels")
    /**
     * @description 查询子分类
     * @Param: parent
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 09:30
     */
    public ResponseData getLevels(int parent){
        return levelService.selectLevels(parent);
    }

    @PostMapping(value = "/getAllLevels")
    /**
     * @description 查询所有类别
     * @Param:
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 09:32
     */
    public ResponseData getAllLevels(){
        return levelService.selectAllLevels();
    }

    @PostMapping(value = "/getLevel")
    /**
     * @description 处理用户查询类别
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-25 09:56
     */
    public ResponseData getLevel(int id){
        return levelService.selectLevel(id);
    }
}
